import { IStrategy } from "./IStrategy";

export class StrategyContext {
    // 使用多态(!: 表示断定变量必有值，后续使用时应判断undefined)
    private strategy?: IStrategy;
    // 策略可切换
    setStrategy(strategy: IStrategy): void {
        this.strategy = strategy;
    }
    // 统一调用入口
    doStrategyMethod(): void {
        if (this.strategy === undefined) {
            throw new Error("使用策略前需设置策略");
        }
        this.strategy.exec();
    }
}